package cn.hp.controller;

import cn.hp.entity.Role2;
import cn.hp.service.Role2Service;
import cn.hp.util.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/rolew")
public class Role2Controller {
    @Autowired
    private Role2Service roleService2;

    @RequestMapping("/page")
    public Result page(Role2 role, @RequestParam(value = "page",defaultValue = "1") Integer page, @RequestParam(value = "limit") Integer limit){
      PageInfo<Role2> rolePageInfo= roleService2.findRole(role,page,limit);
        return Result.success(rolePageInfo);
    }
    @GetMapping
    public Result find(Role2 role){
        List<Role2> list= roleService2.findRole(role);
        return Result.success(list);
    }
    @PostMapping
    public Result add(@RequestBody Role2 role){
        int i=roleService2.insertRole(role);
        return i>0 ? Result.success("添加成功") : Result.error("添加失败");
    }
    @PutMapping
    public Result update(@RequestBody Role2 role){
        int i=roleService2.updateRole(role);
        return i>0 ? Result.success("修改成功") : Result.error("修改失败");
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        int i=roleService2.deleteRoleById(id);
        return i>0 ? Result.success("删除成功") : Result.error("删除失败");
    }
}
